//
//  ChangePwViewController.m
//  HMShoperApp
//
//  Created by chirui on 2018/6/21.
//  Copyright © 2018年 Shui. All rights reserved.
//

#import "ChangePwViewController.h"
#import "LogingViewController.h"

@interface ChangePwViewController ()
@property (weak, nonatomic) IBOutlet UITextField *oldPwText;
@property (weak, nonatomic) IBOutlet UITextField *pwText;
@property (weak, nonatomic) IBOutlet UITextField *sureText;

@end

@implementation ChangePwViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    TitleView(@"修改密码");
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_return_back" target:self action:@selector(backBtnClick)];
    
}

-(void)backBtnClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (IBAction)sureBtnClick:(id)sender {
    
    if (_oldPwText.text==nil||_oldPwText.text.length<1) {
        
        [SHJudgeTools MBProgressHUDPromptWith:@"请输入原密码" On:self.view];
        
        return;
    }
    if (_pwText.text==nil||_pwText.text.length<1) {
        
        [SHJudgeTools MBProgressHUDPromptWith:@"请输入新密码" On:self.view];
        
        return;
    }
    if (_sureText.text==nil||_sureText.text.length<1) {
        
        [SHJudgeTools MBProgressHUDPromptWith:@"请输入确认密码" On:self.view];
        
        return;
    }
    if (![_pwText.text isEqualToString:_sureText.text]) {
        
        [SHJudgeTools MBProgressHUDPromptWith:@"两次密码不一致" On:self.view];
        
        return;
    }
    
    [self changePwRequest];
    
}

-(void)changePwRequest{
    
    NSDictionary * dic = @{@"mid":USER_DEFAULTGet(@"mid"),
                           @"token":USER_DEFAULTGet(@"token"),
                           @"oldPwd":_oldPwText.text,
                           @"newPwd":_pwText.text
                           };
    [PostNetWorking postNetWorkingStr:RequestUrlStr(change_pwd_api) andparameters:dic Success:^(id responseObject) {
        
        if ([responseObject[@"code"] intValue]==200) {
            SHuiMBhudTextTimeStr(@"修改成功，请重新登录");
            dispatch_async(dispatch_get_global_queue(0, 0), ^{
                
                USER_DEFAULTSet(@"", @"mid");
                USER_DEFAULTSet(@"", @"shop_id");
                USER_DEFAULTSet(@"", @"token");
                USER_DEFAULTSet(@"", @"phone");
                USER_DEFAULTSet(@"", @"shop_name");
                USER_DEFAULTSet(@"", @"shop_type");
                USER_DEFAULTSet(@"", @"type");
                USER_DEFAULTSet(@"", @"enter");
                USER_DEFAULTSet(@"", @"tokenVerify");
                
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW , (1 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
                    LogingViewController * tabbar  =[[LogingViewController alloc]init];
                    [UIApplication sharedApplication].keyWindow.rootViewController = tabbar;
                });
            });
        } else {
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        SHuiMBhudTextNetError;
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
  
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
